using System.Collections.Generic;
using XUser = BBX.Entity.User;
using System.Data;
using BBX.Common;
using BBX.Entity;
using BBX.Forum;
using System;

namespace BBX.Web
{
    public class showuser : PageBase
    {
        public List<IUser> userlist;
        public Int32 pageid = DNTRequest.GetInt("page", 1);
        public Int32 totalusers;
        public Int32 pagecount;
        public String pagenumbers;
        public String orderby = "";
        public String ordertype = "";

        protected override void ShowPage()
        {
            pagetitle = "用户";
            if (config.Memliststatus != 1)
            {
                base.AddErrLine("系统不允许查看用户列表");
                return;
            }
            orderby = DNTRequest.GetHtmlEncodeString("orderby", true).Trim();
            if (!"id|name|credits|posts|adminid|joindate|lastactivity".Contains(orderby))
            {
                orderby = "";
            }
            if (!orderby.IsNullOrEmpty() && !Utils.InArray(orderby, "id,name,credits,posts,adminid,joindate,lastactivity"))
            {
                orderby = "id";
            }
            ordertype = DNTRequest.GetHtmlEncodeString("ordertype", true).Trim();
            if (!"asc|desc".Contains(ordertype))
            {
                ordertype = "";
            }
            if (!ordertype.Equals("desc") && !ordertype.Equals("asc"))
            {
                ordertype = "desc";
            }
            //this.totalusers = Users.GetUserCountByAdmin(DNTRequest.GetString("orderby"));
            totalusers = XUser.Meta.Count;
            pagecount = ((totalusers % 20 == 0) ? (totalusers / 20) : (totalusers / 20 + 1));
            pagecount = ((pagecount == 0) ? 1 : pagecount);
            pageid = ((pageid < 1) ? 1 : pageid);
            pageid = ((pageid > pagecount) ? pagecount : pageid);
            //this.userlist = Users.GetUserList(20, this.pageid, this.orderby, this.ordertype);
            userlist = XUser.GetUserList(20, pageid, orderby, ordertype);
            pagenumbers = Utils.GetPageNumbers(pageid, pagecount, string.Format("showuser.aspx{0}", string.Format("?orderby={0}&ordertype={1}", orderby, ordertype)), 8);
        }
    }
}